/*
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 */
package l2s.gameserver.scripts.custom;

import l2s.gameserver.model.actor.L2Npc;
import l2s.gameserver.model.actor.instance.L2PcInstance;
import l2s.gameserver.model.quest.Quest;
import l2s.gameserver.model.quest.QuestState;
import l2s.gameserver.scripting.ScriptFile;

public class MissQueen extends Quest implements ScriptFile
{
	private static final String qn = "MissQueen";
	
	// Rewards
	private static final int COUPON_ONE = 7832;
	private static final int COUPON_TWO = 7833;
	
	// Miss Queen locations
	private static final int[][] LOCATIONS =
	{
		{
			116224,
			-181728,
			-1378,
			0
		},
		{
			114885,
			-178092,
			-832,
			0
		},
		{
			45472,
			49312,
			-3072,
			53000
		},
		{
			47648,
			51296,
			-2994,
			38500
		},
		{
			11340,
			15972,
			-4582,
			14000
		},
		{
			10968,
			17540,
			-4572,
			55000
		},
		{
			-14048,
			123184,
			-3120,
			32000
		},
		{
			-44979,
			-113508,
			-199,
			32000
		},
		{
			-84119,
			243254,
			-3730,
			8000
		},
		{
			-84336,
			242156,
			-3730,
			24500
		},
		{
			-82032,
			150160,
			-3127,
			16500
		}
	};
	
	public MissQueen()
	{
		super(-1, qn, "custom");
		
		// Spawn the 11 NPCs.
		for (int[] spawn : LOCATIONS)
		{
			addSpawn(31760, spawn[0], spawn[1], spawn[2], spawn[3], false, 0, false);
		}
		
		addStartNpc(31760);
		addTalkId(31760);
		addFirstTalkId(31760);
	}
	
	@Override
	public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
	{
		String htmltext = event;
		QuestState st = player.getQuestState(qn);
		
		if (event.equalsIgnoreCase("newbie_coupon"))
		{
			if ((player.getClassId().level() == 0) && (player.getLevel() >= 6) && (player.getLevel() <= 25) && (player.getPkKills() <= 0))
			{
				if (st.getInt("reward_1") == 1)
				{
					htmltext = "31760-01.htm";
				}
				else
				{
					st.setState(STATE_STARTED);
					htmltext = "31760-02.htm";
					st.set("reward_1", "1");
					st.giveItems(COUPON_ONE, 1);
				}
			}
			else
			{
				htmltext = "31760-03.htm";
			}
		}
		else if (event.equalsIgnoreCase("traveller_coupon"))
		{
			if ((player.getClassId().level() == 1) && (player.getLevel() >= 6) && (player.getLevel() <= 25) && (player.getPkKills() <= 0))
			{
				if (st.getInt("reward_2") == 1)
				{
					htmltext = "31760-04.htm";
				}
				else
				{
					st.setState(STATE_STARTED);
					htmltext = "31760-05.htm";
					st.set("reward_2", "1");
					st.giveItems(COUPON_TWO, 1);
				}
			}
			else
			{
				htmltext = "31760-06.htm";
			}
		}
		
		return htmltext;
	}
	
	@Override
	public String onFirstTalk(L2Npc npc, L2PcInstance player)
	{
		QuestState st = player.getQuestState(qn);
		if (st == null)
		{
			st = newQuestState(player);
		}
		
		return "31760.htm";
	}
	
	public static void onLoad()
	{
		new MissQueen();
	}
}